﻿using élénkPróbája.native;
using élénkPróbája.native.@select;

namespace élénkPróbája
{
    public class LitmusValidationContext<T> : ValidationContext
    {
        public LitmusValidationContext(T instanceToValidate) : this(instanceToValidate, new PropChain(), new LitmusDefaultValidatorSelector())
        {

        }

        public LitmusValidationContext(T instanceToValidate, PropChain propertyChain, ILitValidatorSelector validatorSelector)
            : base(instanceToValidate, propertyChain, validatorSelector)
        {

            InstanceToValidate = instanceToValidate;
        }

        public new T InstanceToValidate { get; private set; }
    }

    public class ValidationContext
    { 
        public PropChain PropChain { get; private set; }
        public object InstanceToValidate { get; private set; }
        public ILitValidatorSelector Selector { get; private set; }
        public virtual bool IsChildContext { get; internal set; }
        public ValidationContext(object instanceToValidate)
         : this(instanceToValidate, new PropChain(), new LitmusDefaultValidatorSelector())
        {

        }

        public ValidationContext(object instanceToValidate, PropChain propertyChain, ILitValidatorSelector validatorSelector)
        {
            PropChain = new PropChain(propertyChain);
            InstanceToValidate = instanceToValidate;
            Selector = validatorSelector;
        }
         
        public ValidationContext Clone(PropChain chain = null, object instanceToValidate = null, ILitValidatorSelector selector = null)
        {
            return new ValidationContext(instanceToValidate ?? this.InstanceToValidate, chain ?? this.PropChain, selector ?? this.Selector);
        }

        public ValidationContext CloneForChildValidator(object instanceToValidate)
        {
            return new ValidationContext(instanceToValidate, PropChain, Selector)
            {
                IsChildContext = true
            };
        }
    }
}